package com.tianpengtech.admin.account;
import com.jfinal.aop.Before;
import com.jfinal.kit.HashKit;
import com.jfinal.plugin.activerecord.Model;
import com.tianpengtech.admin.AbstractAdminController;
import com.tianpengtech.admin.InitInterceptor;
import com.tianpengtech.admin.role.RoleDao;
import com.tianpengtech.common.GlobalConfigConstant;
import com.tianpengtech.common.exception.ValidateException;
import com.tianpengtech.common.model.account.Account;
import com.tianpengtech.common.util.XxxUtil;
import org.apache.log4j.Logger;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;

/**
* 路由配置地址：add("/admin/account", AccountAdminController.class, "/admin/account");
* 数据库映射地址：arp.addMapping(Account.dao.tableName(),Account.class);
*/
@Before(InitInterceptor.class)
@RequiresRoles(GlobalConfigConstant.REQUIRES_ROLES_ADMIN)
//@RequiresAuthentication
public class AccountAdminController extends AbstractAdminController{
	private Logger logger = Logger.getLogger(AccountAdminController.class);
	@Override
	protected void config() {
		this.clazz=Account.class;
		this.service=new AccountAdminServiceImpl();
	}

	@Override
	public void beforeAdd() {
		setAttr("roleList", RoleDao.ME.readAllRoles());
	}

	@Override
	public void beforeAdd(Model< ? > model) throws ValidateException {

		String userPass = GlobalConfigConstant.DEFAULT_PASS_WORD;
		userPass = XxxUtil.passMd5(userPass);
		logger.debug(userPass);
		model.set(Account.USERPASS,userPass);
	}

	@Override
	public void beforeQueryById(Model<?> model, int id) {
		setAttr("roleList", RoleDao.ME.readAllRoles());
	}


	@Override
	public void beforeUpdate(Model< ? > model) throws ValidateException {

	}

	@Override
	public void beforeDelete(Model< ? > model) {

	}

}

	